﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace dotNetTraining.ASP_NET
{
    public partial class Login : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (ViewState["username"] != Login_.UserName && ViewState["password"] != Login_.Password)
            {
                ViewState["username"] = Login_.UserName;
                ViewState["password"] = Login_.Password;
            }
        }
        protected void Login_Authenticate(object sender, AuthenticateEventArgs e)
        {
            // save to session
            Session["username"] = Login_.UserName;
            Session["password"] = Login_.Password;
            //save to cookies
            Response.Cookies["username"].Value = Login_.UserName;
            Response.Cookies["username"].Expires = DateTime.Now.AddDays(1);


            Response.Cookies["password"].Value = Login_.Password;
            Response.Cookies["password"].Expires = DateTime.Now.AddDays(1);

            //save to application
            Application["username"] = Login_.UserName;
            Application["password"] = Login_.Password;
            FormsAuthentication.RedirectFromLoginPage(Login_.UserName, Login_.RememberMeSet);
        }
    }
}